package com.chen.base.utils.security;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.StandardCharsets;

/**
 * @author ChenJinLong
 */
public class Base64Util {

    /** 字符串 转 base64 **/
    public static String strToBase64(String data){
        return Base64.encodeBase64URLSafeString(data.getBytes());
    }

    /** base64 转 字符串 **/
    public static String base64ToStr(String base64){
        return new String(Base64.decodeBase64(base64), StandardCharsets.UTF_8);
    }

    public static void main(String[] args) {
        String str = "D:\\IE下载地址\\JAVA-TEMP\\libpcre3_8.39-13build5_amd64.deb";
        String base64 = strToBase64(str);
        System.out.println(base64);
        System.out.println(base64ToStr(base64));
    }
}
